<style>
    .login-box {
        margin-top: -10rem;
        padding: 5px;

    }
    .login-card-body {
        padding: 1.5rem 1.8rem 1.6rem;
    }
    .login-logo {
        color: white;
        font-weight: 700;
    }
    .card, .card-body {
        border-radius: .25rem
    }
    .login-btn {
        padding-left: 2rem!important;;
        padding-right: 1.5rem!important;
    }
    .content {
        overflow-x: hidden;
    }
    .login-page{
        background-image: url("//oss.charityzimi.cn/other_files/CQNZuUbbTrE3QIrgoKGlrNQA2gZIeu40j2Z5nsQo.png");

    }
    .form-group .control-label {
        text-align: left;
    }
    .resend-code {
        float: right;
        background: #0b63f3;
    }
</style>

<div class="login-page ">
    <div class="login-box">
        <div class="login-logo mb-2">
            {{ config('app.name') }}
        </div>
        <div class="card" style="padding: 20px">
            <div class="login-container">
                <ul class="nav nav-tabs" id="loginTabs" role="tablist">
                    <li class="nav-item">
                        <a class="nav-link active" id="code-tab" data-toggle="tab" href="#code-login" role="tab"
                           aria-controls="code-login" aria-selected="true">验证码登录</a>
                    </li>
                    <li class="nav-item">
                        <a class="nav-link" id="password-tab" data-toggle="tab" href="#password-login" role="tab"
                           aria-controls="password-login" aria-selected="false">密码登录</a>
                    </li>
                </ul>
                <div class="tab-content mt-3" id="loginTabsContent">
                    <div class="tab-pane fade show active" id="code-login" role="tabpanel" aria-labelledby="code-tab">
                        <form id="login-form-mobile" method="POST" action="{{ admin_url('auth/login-mobile') }}">
                            <input type="hidden" name="type" value="{{ request('type') }}"/>
                            <fieldset class="form-label-group form-group position-relative has-icon-left">
                                <input
                                        type="text"
                                        id="mobile"
                                        class="form-control {{ $errors->has('mobile') ? 'is-invalid' : '' }}"
                                        name="mobile"
                                        placeholder="手机号"
                                        value="{{ old('mobile') }}"
                                        required
                                        autofocus
                                >

                                <div class="form-control-position">
                                    <i class="feather icon-smartphone"></i>
                                </div>

                                <label for="email">{{ trans('admin.username') }}</label>

                                <div class="help-block with-errors"></div>
                                @if($errors->has('username'))
                                    <span class="invalid-feedback text-danger" role="alert">
                                            @foreach($errors->get('username') as $message)
                                            <span class="control-label" for="inputError"><i
                                                        class="feather icon-x-circle"></i> {{$message}}</span><br>
                                        @endforeach
                                        </span>
                                @endif
                            </fieldset>
                            <fieldset class="form-label-group form-group position-relative has-icon-left">

                                <label for="verificationCode">验证码</label>
                                <div class="input-group">
                                    <input
                                            minlength="6"
                                            maxlength="20"
                                            id="mobile"
                                            type="text"
                                            class="form-control {{ $errors->has('verificationCode') ? 'is-invalid' : '' }}"
                                            name="verificationCode"
                                            placeholder="验证码"
                                            required
                                            autocomplete="current-password"
                                    >
                                    <div class="form-control-position">
                                        <i class="feather icon-smartphone"></i>
                                    </div>

                                    <div class="input-group-append">
                                        <button type="button" class="btn btn-outline-secondary resend-code"
                                                id="resendCodeBtn">获取验证码
                                        </button>
                                    </div>
                                </div>
                                <div class="help-block with-errors"></div>
                                @if($errors->has('verificationCode'))
                                    <span class="invalid-feedback text-danger" role="alert">
                                            @foreach($errors->get('verificationCode') as $message)
                                            <span class="control-label" for="inputError"><i
                                                        class="feather icon-x-circle"></i> {{$message}}</span><br>
                                        @endforeach
                                            </span>
                                @endif
                            </fieldset>
                            <button type="submit" class="btn btn-primary btn-block log-btn">立即登录</button>
                        </form>
                    </div>
                    <div class="tab-pane fade" id="password-login" role="tabpanel" aria-labelledby="password-tab">
                        <form id="login-form" method="POST" action="{{ admin_url('auth/login') }}">

                            <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
                            <input type="hidden" name="type" value="{{ request('type') }}"/>

                            <fieldset class="form-label-group form-group position-relative has-icon-left">
                                <input
                                        type="text"
                                        class="form-control {{ $errors->has('mobile') ? 'is-invalid' : '' }}"
                                        name="mobile"
                                        placeholder="手机号"
                                        value="{{ old('mobile') }}"
                                        required
                                        autofocus
                                >

                                <div class="form-control-position">
                                    <i class="feather icon-user"></i>
                                </div>

                                <label for="email">{{ trans('admin.username') }}</label>

                                <div class="help-block with-errors"></div>
                                @if($errors->has('username'))
                                    <span class="invalid-feedback text-danger" role="alert">
                                            @foreach($errors->get('username') as $message)
                                            <span class="control-label" for="inputError"><i
                                                        class="feather icon-x-circle"></i> {{$message}}</span><br>
                                        @endforeach
                                        </span>
                                @endif
                            </fieldset>

                            <fieldset class="form-label-group form-group position-relative has-icon-left">
                                <input
                                        minlength="5"
                                        maxlength="20"
                                        id="password"
                                        type="password"
                                        class="form-control {{ $errors->has('password') ? 'is-invalid' : '' }}"
                                        name="password"
                                        placeholder="{{ trans('admin.password') }}"
                                        required
                                        autocomplete="current-password"
                                >

                                <div class="form-control-position">
                                    <i class="feather icon-lock"></i>
                                </div>
                                <label for="password">{{ trans('admin.password') }}</label>

                                <div class="help-block with-errors"></div>
                                @if($errors->has('password'))
                                    <span class="invalid-feedback text-danger" role="alert">
                                            @foreach($errors->get('password') as $message)
                                            <span class="control-label" for="inputError"><i
                                                        class="feather icon-x-circle"></i> {{$message}}</span><br>
                                        @endforeach
                                            </span>
                                @endif

                            </fieldset>
                            <button type="submit" class="btn btn-primary btn-block login-btn log-btn">

                                {{ __('admin.login') }}
                                &nbsp;
                                <i class="feather icon-arrow-right"></i>
                            </button>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    Dcat.ready(function () {
        $('#resendCodeBtn').click(function () {
            var $btn = $(this);
            let mobile = $('#mobile').val();
            if (!mobile) {
                layer.msg('手机号不能为空');
                return;
            }
            $.ajax({
                type: 'POST', // 请求的方式
                url: '{{ admin_url('auth/mobile-verify-code') }}',  // 请求的 URL 地址
                data: { // 要提交给服务器的数据
                    'mobile': mobile,
                    '_token': '{{csrf_token()}}'
                },
                dataType: 'json',
                success: function (res) { // 请求成功之后的回调函数
                    layer.msg(res.message);
                    if (res.code == 200) {
                        var countdown = 60;
                        $btn.prop('disabled', true);
                        $btn.text(countdown + '秒后可重新获取');
                        $btn.css('background', '#FFFeee');
                        var interval = setInterval(function () {
                            countdown--;
                            $btn.text(countdown + '秒后可重新获取');
                            if (countdown === 0) {
                                clearInterval(interval);
                                $btn.prop('disabled', false);
                                $btn.text('获取验证码');
                                $btn.css('background', '#0b63f3');

                            }
                        }, 1000);
                    }
                }
            })
            {{--$.post( "{{ admin_url('auth/mobile-verify-code') }}", { 'mobile':mobile }, function( data ) {--}}
            {{--    console.log( data ); // John--}}
            {{--}, "json" );--}}

        });
        // ajax表单提交
        $('#login-form').form({
            validate: true,
        });
        $('#login-form-mobile').form({
            validate: true,
        });
    });
</script>
